package com.anan.service.impl;

import com.anan.constants.Constants;
import com.anan.mapper.ImgResourceMapper;
import com.anan.mapper.ProductMapper;
import com.anan.mapper.StudentMapper;
import com.anan.pojo.bo.ImgInfosBO;
import com.anan.pojo.domain.ImgResourceDO;
import com.anan.pojo.domain.ProductDO;
import com.anan.pojo.domain.StudentDO;
import com.anan.pojo.dto.ImgDTO;
import com.anan.pojo.dto.ShowImgsDTO;
import com.anan.pojo.vo.ImgInfosVO;
import com.anan.service.ImgResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author anan
 * @date 2023/05/08/10:06
 **/
@Service
@Slf4j
public class ImgResourceServiceImpl implements ImgResourceService {
    @Resource
    ImgResourceMapper imgResourceMapper;

    @Resource
    StudentMapper studentMapper;

    @Resource
    ProductMapper productMapper;


    @Override
    public boolean addImg(ImgDTO imgDTO) {
        if (null != imgDTO) {
            List<ImgInfosBO> imgInfosBOs = imgDTO.getImgInfosBOs();
            if (null != imgInfosBOs && imgInfosBOs.size() > 0) {
                ImgInfosBO imgInfosBO = imgInfosBOs.get(0);
                if (Constants.TYPE.STUDENT == imgInfosBOs.get(0).getImgType()) {
                    return imgResourceMapper.updateImg(imgInfosBO.getImgUrl(), imgInfosBO.getImgType(), imgInfosBO.getRelateId());
                }
            }else log.info("===== 入参为空！ =====");
           return imgResourceMapper.addImgs(imgDTO);
        }
        return false;
    }

    @Override
    public ImgInfosVO getImgInfos(ShowImgsDTO showImgsDTO) {
        if (null != showImgsDTO && null != showImgsDTO.getStudentId()) {
            List<ProductDO> product = productMapper.getProductByStudentId(showImgsDTO.getStudentId());
            if (null != product) {
                product.forEach(productDO -> {
                    List<ImgResourceDO> imgResources = imgResourceMapper.getUrlByIdAndType(showImgsDTO.getImgType(), showImgsDTO.getStudentId());

                });

            }
        }
        return null;
    }
}
